<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>
<style>
.top-area{
	 height:100px;
	 width:100%;
	 display:flex;
	 flex-direction: row;
	 margin-top:30px;
}
.top-item{
	height:80px;
	width:25%;
	font-size:20px;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>
<div class="top-area">
	<div class="top-item">订单号：${orderNo}</div>
	<div class="top-item">总利润：${totalProfit}</div>
</div>
<div id="expressDetail" class="goodorder">
</div>	
<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <thead>
		    <tr>
		        <th>商品名称</th>
				<th>商品总数量</th>
				<th>商品总金额</th>
				<th>商品单价</th>
				<th>图片</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		STORE_LIST: basePath + '${common_url}storeList',
		INIT_CITY: basePath + '${common_url}initCity',
		INIT_CITY_STORE_DETAIL: basePath + '${common_url}initCityStoreDetail',
		ORDER_DETAIL: basePath + '${common_url}orderDetail',
		INIT_ORDER_DETAIL: basePath + '${common_url}initOrderdetail',
		INIT_VIEW: basePath + '${common_url}initView'
	};
	
    var  orderExpressList,
    	 orderid,
    	 storeId,
    	 saleId,
    	 cityId,
    	 permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	console.log(permission);
    	orderid = ${orderid};
    	storeId = ${storeId};
    	saleId = ${saleId};
    	cityId = ${cityId};
    	orderExpressList = ${express};
    	
    	//物流信息加载
    	for(var a=0;a<orderExpressList.length;a++){
  	      var express = null;
  	      var allHTML = null;
  		  //订单项发货填写物流设置隐藏
  	        var expressHTML = '<div class="innertable">' + '<p>物流</p>'
  	            + '<p>物流编号：' + orderExpressList[a].expressNo + '</p>'
  	            + '<p>商品编号：' + orderExpressList[a].skuId + '</p>';
  	        for (var b = 0; b < orderExpressList[a].object.length; b++) {
  	          if (express != null) {
  	            express = express + '<p>'
  	                + orderExpressList[a].object[b].datetime
  	                + '</p>' + '<p>'
  	                + orderExpressList[a].object[b].remark
  	                + '</p>';
  	          } else {
  	            express = '<p>'
  	                + orderExpressList[a].object[b].datetime
  	                + '</p>' + '<p>'
  	                + orderExpressList[a].object[b].remark
  	                + '</p>';
  	          }
  	        }
  	        if (express != null) {
  	          allHTML = expressHTML + express + '</div>';
  	          $("#expressDetail").append(allHTML);
  	        } else {
  	          allHTML = expressHTML + '</div>';
  	          $("#expressDetail").append(allHTML);
  	        }    	      
  	    }
    	
    	//初始化下拉选项
    	$('#identity').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_PARTNER_APPLY_TYPE'
        });
    	
        //orderDetail
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initOrderdetail"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_ORDER_DETAIL + '?id=' + id;
        });
      //initView
        $('#t-wrap').on('click', 'a[data-permit="${name_english}:initView"]', function() {
            var $this = $(this),
            id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_VIEW + '?id=' + id;
        });
        // 查询按钮
        $('#search').on('click', reloadTable);
      	//返回按钮
   		$('#backBtn, #goBack').on('click',backMain);
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#partnerName').val('');
        	$('#totalInMoneySlef').val('');
        	$('#totalOrders').val('');
        	$('#totalProfit').val('');
        	reloadTable();
        });
        
       createTable();
        
    });
  	//返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"orderid": orderid
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.ORDER_DETAIL,
    			param: {
    				"partnerName": trimSpace($('#partnerName').val()),
            		"totalInMoneySlef": trimSpace($('#totalInMoneySlef').val()),
            		"totalOrders": trimSpace($('#totalOrders').val()),
            		"totalProfit": trimSpace($('#totalProfit').val()),
            		"orderid": orderid
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'spuName'
    		     },
    		     {
    		    	 field: 'totalCount'
    		     },
    		     {
    		    	 field: 'totalMoney'
    		     },
    		     {
    		    	field:'onePrice' 
    		     },
    		     {
    		    	 field:'spuMainImage',
    		    	 render: function(rowData){
    		    		 var html = '<img src="'+rowData.spuMainImage+'" style="height:100px;width:100px;">'
    		    	 	 return html;
    		    	 }
    		     }     
    	    ]
    	});
    }
  //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_CITY_STORE_DETAIL+"?id="+storeId+"&saleId="+saleId+"&cityId="+cityId;
    }
</script>
</body>
</html>